package com.school.filter;

import com.school.util.RegexUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class XssHttpServletRequestWraper extends HttpServletRequestWrapper {

    public XssHttpServletRequestWraper(HttpServletRequest request) {
        super(request);
    }

    @Override
    public String getHeader(String name) {
        System.out.println(RegexUtil.sqlFiledCheck(super.getHeader(name)) + " @1");
        return RegexUtil.sqlFiledCheck(super.getHeader(name));
    }

    @Override
    public String getParameter(String name) {
        System.out.println(RegexUtil.sqlFiledCheck(super.getParameter(name)) + " @2");
        return RegexUtil.sqlFiledCheck(super.getParameter(name));
    }

    @Override
    public String[] getParameterValues(String name) {
        if (name != null && !name.equals("")) {
            String[] values = super.getParameterValues(name);
            if (values != null && values.length > 0) {
                String[] newValues = new String[values.length];
                for (int i = 0; i < values.length; i++) {
                    System.out.println(RegexUtil.sqlFiledCheck(name) + " @3");
                    newValues[i] = RegexUtil.sqlFiledCheck(values[i]);
                }
                return newValues;
            }
        }
        return null;
    }
}
